package com.ten_4_4.hiring.comm;

import java.util.List;

public class PageModel<T> {
	private List<T> list;
	private int pageNo;
	private int pageSize;
	private int allRecords;
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getAllRecords() {
		return allRecords;
	}
	public void setAllRecords(int allRecords) {
		this.allRecords = allRecords;
	}
	public int getTotalPages() {
		return (allRecords + pageSize - 1) / pageSize;
	}
	/**
	 * 总共有多少页
	 * 
	 * @return
	 */
	public int getTotalPage() {
		// return (allRecords + pageSize - 1) / pageSize;
		return (int) Math.ceil((double) allRecords / pageSize);
	}
	
	public int getFirst() {
		return 1;
	}
	public int getLast() {
		return getTotalPages();
	}
	public int getPre() {
		if(pageNo == 1) {
			return 1;
		}
		return pageNo - 1;
	}
	public int getNext() {
		if(pageNo == getTotalPages()) {
			return getTotalPages();
		}
		return pageNo + 1;
	}
	public PageModel() {
	}
	public PageModel(List<T> list, int pageNo, int pageSize, int allRecords) {
		this.list = list;
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.allRecords = allRecords;
	}
	
}
